<%--
  - Author		:	Jaewon Choi
  - Date			:
  - Description	:	
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/jqueryUi/css/ui-lightness/jquery-ui-1.8.21.custom.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-ui-1.8.21.custom.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
				$( ".date" ).datepicker({
					showOn: "both",
					buttonImage: "<c:url value="${dirImages}/calendar.png" />",
					buttonImageOnly: true,
					dateFormat: "yy-mm-dd"
				});
			});

			function validation(){
				<c:if test="${param.fAct eq 'view'}">
					return true;
				</c:if>
				try{
					if((document.frm.msg.value).replace(/\s/g, '') == ""){
						alert("[메시지]는 필수 입력 항목입니다.");
						document.frm.msg.focus();
						return false;
					}
					
					if(document.frm.msg.value.length > 300){
						alert("[메시지]의 최대 글자 수는 300자 입니다.\n현재 글자 수 : "+document.frm.msg.value.length);
						document.frm.msg.focus();
						return false;
					}

					if((document.frm.revPushTime_date.value).replace(/\s/g, '') == ""){
						alert("[예약일시]는 필수 입력 항목입니다.");
						document.frm.revPushTime_date.focus();
						return false;
					}
					
					document.frm.revPushTime.value = document.frm.revPushTime_date.value +" " + document.frm.revPushTime_hour.value + ":00:00";

				}catch(err){
					return false;	
				}
				
				return confirm(confirmMsg);
			}
			var confirmMsgs = ["등록 하시겠습니까?", "수정 하시겠습니까?", "삭제 하시겠습니까?"];
			var confirmMsg = "";
		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">
					Apple푸시메시지 > 
					<c:choose>
						<c:when test="${param.fAct eq 'view'}">상세보기</c:when>
						<c:when test="${not empty apns}">수정</c:when>
						<c:otherwise>등록</c:otherwise>
					</c:choose>
				</div>
				<form id="frm" name="frm" method="post" enctype="multipart/form-data" action="<c:url value="/apns/submit.do" />" onsubmit="return validation();">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchGubun" value="${param.searchGubun}" />
					<input type="hidden" name="id" value="${apns.id}">
					
					<table class="frmTbl" border="0">
						<colgroup>
							<col width="130px;" />
							<col width="*" />
							<col width="130px;" />
							<col width="*" />
						</colgroup>
						<tbody>
							<!-- <tr>
								<th>구분</th>
								<td colspan="3" style="padding: 10px 0;">
									<c:choose>
										<c:when test="${param.fAct eq 'view'}">
											<c:choose>
												<c:when test="${apns.gubun eq 'e'}">에스콰이어</c:when>
												<c:when test="${apns.gubun eq 'h'}">하퍼스바자</c:when>
												<c:when test="${apns.gubun eq 'm'}">모터트렌드</c:when>
												<c:when test="${apns.gubun eq 't'}">APNS테스트</c:when>
												<c:otherwise>${apns.gubun}</c:otherwise>
											</c:choose>
										</c:when>
										<c:otherwise>
											<select name="gubun">
												<option value="e" <c:if test="${apns.gubun eq 'e'}"> selected="selected" </c:if>>에스콰이어</option>
												<option value="h" <c:if test="${apns.gubun eq 'h'}"> selected="selected" </c:if>>하퍼스바자</option>
												<option value="m" <c:if test="${apns.gubun eq 'm'}"> selected="selected" </c:if>>모터트렌드</option>
												<option value="t" <c:if test="${apns.gubun eq 't'}"> selected="selected" </c:if>>APNS테스트</option>
											</select>
										</c:otherwise>
									</c:choose>
								</td>
							</tr> -->
							<input type="hidden" name="gubun" value="n">
							<tr>
								<th>메시지</th>
								<td colspan="3" style="padding: 10px 0;">
									<c:choose>
										<c:when test="${param.fAct eq 'view'}">
											<textarea name="msg" style="border: none; width: 745px; height: 150px" onfocus="javascript:this.blur();">${apns.msg}</textarea>
										</c:when>
										<c:otherwise>
											<textarea name="msg" style="width: 745px; height: 150px" >${apns.msg}</textarea>
										</c:otherwise>
									</c:choose>
								</td>
							</tr>
							<tr>
								<th>예약일시</th>
								<td colspan="3">
									<c:choose>
										<c:when test="${param.fAct eq 'view'}">
											<c:catch var="e">
												<fmt:parseDate var="revPushTime" pattern="yyyy-MM-dd HH:mm:ss" value="${apns.revPushTime}" />
												<fmt:formatDate value="${revPushTime}" pattern="yyyy-MM-dd HH:mm:ss" />
											</c:catch>
											<c:if test="${not empty e}">
												${apns.revPushTime}
											</c:if>
										</c:when>
										<c:otherwise>
											<c:catch var="e">
												<fmt:parseDate var="revPushTime" pattern="yyyy-MM-dd HH:mm:ss" value="${apns.revPushTime}" />
												<fmt:formatDate var="revPushTime_date" value="${revPushTime}" pattern="yyyy-MM-dd" />
												<fmt:formatDate var="revPushTime_hour" value="${revPushTime}" pattern="HH" />
											</c:catch>
											<input type="hidden" name="revPushTime" value="${apns.revPushTime}" />
											<input type="text" id="revPushTime_date" class="date" readonly="readonly" value="${revPushTime_date}" />
											<select id="revPushTime_hour">
												<c:forEach var="i" begin="0" end="23" step="1">
													<fmt:formatNumber var="hour" value="${i}" pattern="00" />
													<option value="${hour}" <c:if test="${revPushTime_hour eq hour}"> selected="selected" </c:if>>${hour}</option>
												</c:forEach>
											</select>시
										</c:otherwise>
									</c:choose>
								</td>
							</tr>
							<c:if test="${not empty apns.pushTime}">
								<tr>
									<th>전송일시</th>
									<td>
										<c:catch var="e">
											<fmt:parseDate var="pushTime" pattern="yyyy-MM-dd HH:mm:ss" value="${apns.pushTime}" />
											<fmt:formatDate value="${pushTime}" pattern="yyyy-MM-dd HH:mm:ss" />
										</c:catch>
										<c:if test="${not empty e}">
											${apns.pushTime}
										</c:if>
									</td>
									<th>전송개수</th>
									<td>
										${apns.pushCnt}
									</td>
								</tr>
							</c:if>
						</tbody>
					</table>
					<input type="button" class="btn" value="목록" onclick="javascript:document.listFrm.submit();" />
					<c:choose>
						<c:when test="${empty apns}">
							<input type="submit" class="btn" value="등록" onclick="javasciprt:confirmMsg=confirmMsgs[0];"/>
						</c:when>
						<c:when test="${param.fAct eq 'view' && apns.status eq '0'}">
							<input type="submit" class="btn" value="수정" onclick="javasciprt:document.frm.action='<c:url value="/apns/form.do" />';" />
						</c:when>
						<c:when test="${apns.status eq '0'}">
							<input type="submit" class="btn" value="수정" onclick="javasciprt:confirmMsg=confirmMsgs[1];"/>
							<input type="button" class="btn" value="삭제" onclick="javascript:if(confirm(confirmMsgs[2])){document.removeFrm.submit();}" />
						</c:when>
					</c:choose>
				</form>
				<form name="listFrm" action="<c:url value="/apns/list.do" />" method="post" style="display: none;">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
				</form>
				
				<form name="removeFrm" action="<c:url value="/apns/remove.do" />" method="post" style="display: none;">
					<input type="hidden" name="fAct" value="remove">
					<input type="hidden" name="id" value="${apns.id}">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
				</form>
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 